home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
MacAddict 123
/
MacAddict_123_2006_11.iso
/
Software
/
Utilities
/
VelaClock 1.9.wdgt
/
Scripts
/
Main.js
< prev
Wrap
Text File
|
2006-08-29
|
71KB
|
2,495 lines
// Copyright 2005-2006, Vela Design Group. All rights reserved.
var placeTimes = new Array();
var widgetWidth = 276;
var backsideHeight = 400; //vc16: 365; vc13: 315
var currentSelection = null;
var showingInfo = true;
var showAMPM = true;
var showLeadingZeros = false;
var hideSeconds = true;
var useDSTInsteadOfSummer = true;
var showMoonLine = true;
var showChangeInMinutes = true;
var sortByCountry = false;
var isShowingFront = true;
//var backsideChanged = false;
var is1043orNewer = true;
var needToCompleteTransition = false;
//pref keys
var selectionPrefKey = "selection";
var showAMPMPrefKey = "showAMPM";
var showLeadingZerosPrefKey = "showLeadingZeros";
var hideSecondsPrefKey = "hideSeconds";
var useDSTInsteadOfSummerPrefKey = "useDSTInsteadOfSummer";
var showChangeInMinutesPrefKey = "showChangeInMinutes";
var showMoonLinePrefKey = "showMoonLine";
var sortByCountryPrefKey = "sortByCountry";
var regionPrefKey = "region15";
var placePrefKey = "place15";
var maxItems = 24;
function getLocalizedString (key)
{
try {
var ret = localizedStrings[key];
if (ret === undefined)
ret = key;
return ret;
} catch (ex) {}
return key;
}
//
// update functions
//
var validMode = true;
var demoMode = true;
//pre-fetch images
(new Image()).src = "Images/digTime12_1.png";
(new Image()).src = "Images/digTime12_5.png";
(new Image()).src = "Images/digTime24_1.png";
(new Image()).src = "Images/digTime24_5.png";
(new Image()).src = "Images/light1.png";
(new Image()).src = "Images/light2.png";
(new Image()).src = "Images/light3.png";
(new Image()).src = "Images/light4.png";
(new Image()).src = "Images/light5.png";
function getEarthLightImage(earthLight)
{
var imageSrc;
switch (earthLight) {
case 1:
imageSrc = "Images/light1.png";
break;
case 2:
imageSrc = "Images/light2.png";
break;
case 3:
imageSrc = "Images/light3.png";
break;
case 4:
imageSrc = "Images/light4.png";
break;
default: //night
imageSrc = "Images/light5.png";
}
return imageSrc;
}
function updateNow()
{
if (window.vtMain && validMode)
//if (window.vtMain && isShowingFront && validMode) //vc14
{
//alert(" js-updateNow");
var header = document.getElementById('placesHeader');
var dataForAllRows = vtPlace.infoForAllRows();
var count = placeTimes.length;
for (var index = 0; index < count; ++index)
{
try
{
var placeTimeID = placeTimes[index];
var placeSpan = document.getElementById(placeTimeID+"_place");
//position dependent code (firstChild)?
placeSpan.firstChild.data = dataForAllRows[index][0];
var time24Span = document.getElementById(placeTimeID+"_time24");
var time12Span = document.getElementById(placeTimeID+"_time12");
var timeAMPMSpan = document.getElementById(placeTimeID+"_timeAMPM");
var timeInfo = dataForAllRows[index][1];
time24Span.firstChild.data = timeInfo[0];
time12Span.firstChild.data = timeInfo[1];
timeAMPMSpan.firstChild.data = timeInfo[2];
var row = header.childNodes[index];
var savedEarthLight = row.earthLight;
var earthLight = dataForAllRows[index][2];
if (earthLight != savedEarthLight) {
row.setAttribute ("earthLight", earthLight);
//set background image for digital time
var lightBox = document[placeTimeID+"_light"];
lightBox.src = getEarthLightImage(earthLight);
if (earthLight == 1 || earthLight == 5)
lightBox.setAttribute ("style", "visibility:hidden;");
else
lightBox.setAttribute ("style", "visibility:visible;");
//set color of digital time text
var digTimeBackground = document[placeTimeID+"_digTimeBack"];
if (earthLight == 1) {
if (showAMPM)
digTimeBackground.src = "Images/digTime12_1.png";
else
digTimeBackground.src = "Images/digTime24_1.png";
time24Span.setAttribute ("class", "digTime24");
time12Span.setAttribute ("class", "digTime12");
timeAMPMSpan.setAttribute ("class", "digTimeAMPM");
} else {
if (showAMPM)
digTimeBackground.src = "Images/digTime12_5.png";
else
digTimeBackground.src = "Images/digTime24_5.png";
time24Span.setAttribute ("class", "digTime24 digNight");
time12Span.setAttribute ("class", "digTime12 digNight");
timeAMPMSpan.setAttribute ("class", "digTimeAMPM digNight");
}
if (showAMPM)
digTimeBackground.setAttribute("style", "left: 177px;");
else
digTimeBackground.setAttribute("style", "left: 195px;");
}
} catch (ex)
{
// don't let one exception lose all the data
}
}
updateInfo();
}
}
// Love love love
// You better hope love is the answer baby
// I think you better hope it comes before the summer
// - Jimi Hendrix
var clockHandHours1 = new Image (13, 46); //(14, 46) (4, 24)
clockHandHours1.src = 'Images/clockHandHours1.png';
var clockHandHours2 = new Image (13, 46); //(14, 46) (4, 24)
clockHandHours2.src = 'Images/clockHandHours2.png';
var clockHandHours3 = new Image (13, 46); //(14, 46) (4, 24)
clockHandHours3.src = 'Images/clockHandHours3.png';
var clockHandHours4 = new Image (13, 46); //(14, 46) (4, 24)
clockHandHours4.src = 'Images/clockHandHours4.png';
var clockHandHours5 = new Image (13, 46); //(14, 46) 14, 46
clockHandHours5.src = 'Images/clockHandHours5.png';
var clockHandHours = clockHandHours1;
var clockHandMinutes1 = new Image (13, 46); //(14, 46) (2, 30)
clockHandMinutes1.src = 'Images/clockHandMinutes1.png';
var clockHandMinutes5 = new Image (13, 46); //(14, 46) (2, 30)
clockHandMinutes5.src = 'Images/clockHandMinutes5.png';
var clockHandMinutes = clockHandMinutes1;
var clockHandSeconds = new Image (13, 46); //(14, 46) (3, 49)
clockHandSeconds.src = 'Images/clockHandSeconds.png';
var clockHandsScrew = new Image (13, 46); //(14, 46) (3, 49)
clockHandsScrew.src = 'Images/clockHandsScrew.png';
function drawClockHands(handAngles)
{
//handAngles[0], handAngles[1], handAngles[2]
//secondsAngle, minutesAngle, hoursAngle
var canvas = document.getElementById("clock-canvas");
var context = canvas.getContext("2d");
context.clearRect (0, 0, 94, 94);
context.save();
context.translate (94/2, 94/2);
//minutes
context.save();
context.rotate (handAngles[1]);
context.translate (-7.0, -39.5);
context.drawImage (clockHandMinutes, 0, 0, 13, 46);
//vc17
//context.translate (-7.0, -43.0); // -45.0
//context.drawImage (clockHandMinutes, 0, 0, 14, 46);
context.restore();
//hours
context.save();
context.rotate (handAngles[2]);
context.translate (-6.5, -39.5);
context.drawImage (clockHandHours, 0, 0, 13, 46);
//vc17
//context.translate (-7.0, -40.0);
//context.drawImage (clockHandHours, 0, 0, 14, 46);
context.restore();
//seconds
if (!hideSeconds)
{
context.save();
context.rotate (handAngles[0]);
context.translate (-7.0, -39.5); // -45.0
context.drawImage (clockHandSeconds, 0, 0, 13, 46);
//vc17
//context.translate (-7.0, -43.0); // -45.0
//context.drawImage (clockHandSeconds, 0, 0, 14, 46);
context.restore();
}
context.translate (-6.5, -39.5);
context.drawImage (clockHandsScrew, 0, 0, 13, 46);
context.restore();
}
//updateSeconds is not called unless the analog clock is showing.
//This is critical to prevent unnecessary use of the processor.
//The plug-in can determine if the analog clock is showing or not.
function updateSeconds(handAngles, timeInfo, seconds)
{
if (window.vtMain) {
if (showingInfo)
{
drawClockHands(handAngles);
document.getElementById("localTimeSeconds").innerText = timeInfo[0];
if (showAMPM) {
document.getElementById("localTime").innerText = timeInfo[2];
document.getElementById("localTimeAMPM").innerText = timeInfo[3];
} else {
document.getElementById("localTime").innerText = timeInfo[1];
document.getElementById("localTimeAMPM").innerText = "";
}
}
}
}
function createRow (rowIndex)
{
var placeTimeID = placeTimes[rowIndex];
var row = document.createElement('div');
row.setAttribute ("class", "placeTitle");
row.setAttribute ("onclick", "clickonrow(event, this);");
//addClock MUST be called before this code (to initialize placeTimes).
row.setAttribute ("placeTimeID", placeTimeID);
//alert("createRow: placeTimeID = " + placeTimeID + " " + vtPlace.infoStringForRow(0, rowIndex));
row.setAttribute ("earthLight", "-1");
var flagImage = document.createElement('img');
flagImage.setAttribute ("class", "flag");
var flagInfo = vtPlace.flagInfoForRow(rowIndex);
flagImage.src = flagInfo[0];
flagImage.setAttribute ("style", "padding-top:" + flagInfo[1]);
row.appendChild (flagImage);
var placeSpan = document.createElement('span');
placeSpan.setAttribute ("class", "place");
placeSpan.setAttribute ("id", placeTimeID + "_place");
placeSpan.innerText = " ";
//Amundsen-Scott Station or Dumont-d'Urville Base
if (placeTimeID == "010" || placeTimeID == "017")
placeSpan.setAttribute ("style", "font-size:13px;");
row.appendChild (placeSpan);
var digTimeBgImage = document.createElement('img');
digTimeBgImage.setAttribute ("class", "digTimeBg");
digTimeBgImage.setAttribute ("id", placeTimeID + "_digTimeBack");
digTimeBgImage.setAttribute ("onclick", "clickonTime(event, this);");
row.appendChild (digTimeBgImage);
var lightImage = document.createElement('img');
lightImage.setAttribute ("class", "light");
lightImage.setAttribute ("id", placeTimeID + "_light");
lightImage.setAttribute ("onclick", "clickonTime(event, this);");
lightImage.src = getEarthLightImage(2); //twilight is default
lightImage.setAttribute ("style", "visibility:hidden;"); //hidden is default
row.appendChild (lightImage);
//time24
var time24Span = document.createElement('span');
time24Span.setAttribute ("class", "digTime24");
time24Span.setAttribute ("id", placeTimeID + "_time24");
time24Span.setAttribute ("onclick", "clickonTime(event, this);");
time24Span.innerText = "23:59 PM";
if (showAMPM)
time24Span.setAttribute ("style", "display:none;");
row.appendChild (time24Span);
//time12
var time12Span = document.createElement('span');
time12Span.setAttribute ("class", "digTime12");
time12Span.setAttribute ("id", placeTimeID + "_time12");
time12Span.setAttribute ("onclick", "clickonTime(event, this);");
time12Span.innerText = "11:59 PM";
if (!showAMPM)
time12Span.setAttribute ("style", "display:none;");
row.appendChild (time12Span);
//timeAMPM
var timeAMPMSpan = document.createElement('span');
timeAMPMSpan.setAttribute ("class", "digTimeAMPM");
timeAMPMSpan.setAttribute ("id", placeTimeID + "_timeAMPM");
timeAMPMSpan.setAttribute ("onclick", "clickonTime(event, this);");
timeAMPMSpan.innerText = "AM";
if (!showAMPM)
timeAMPMSpan.setAttribute ("style", "display:none;");
row.appendChild (timeAMPMSpan);
return row;
}
//pre-fetch images
(new Image()).src = "Images/backside1.png";
(new Image()).src = "Images/backside2.png";
var curBacksideItem = 0;
//var resizedWhenFlippedOver = false;
var alertWasShowing = false;
function showbackside(event) {
var front = document.getElementById("front");
var back = document.getElementById("back");
var frontIsShorter = calculateWidgetHeight() < backsideHeight;
//curBacksideItem = 1;
//document.getElementById ('content-backsideMenu').options[curBacksideItem].selected = true;
changeBacksideContent();
//alert("showbackside: widgetHeight = " + calculateWidgetHeight());
/*
resizedWhenFlippedOver = true;
if (window.widget)
{
widget.prepareForTransition("ToBack");
//resize after flip
window.resizeTo (widgetWidth, backsideHeight); //450 323
}
*/
alertWasShowing = alertIsShowing;
if (alertWasShowing)
hideAlert();
if (window.widget) {
if (frontIsShorter)
window.resizeTo (widgetWidth, backsideHeight);
widget.prepareForTransition("ToBack");
}
/*
resizedWhenFlippedOver = true;
if (window.widget)
{
if (calculateWidgetHeight() < backsideHeight)
{
window.resizeTo (widgetWidth, backsideHeight);
resizedWhenFlippedOver = true;
}
//resizing after the flip sometimes truncates the back!
widget.prepareForTransition("ToBack");
}
*/
front.style.display="none";
if (!frontIsShorter && window.widget)
window.resizeTo (widgetWidth, backsideHeight);
back.style.display="block";
isShowingFront = false;
updateTitle.innerText = "Software Update";
document.getElementById('sortText').innerHTML = 'Group by Country/State';
document.getElementById('timeFormatText').innerHTML = 'Show 24-hour time format';
document.getElementById('leadingZerosText').innerHTML = 'Show leading zeros time format';
document.getElementById('hideSecondsText').innerHTML = 'Hide seconds (reduce CPU usage)';
document.getElementById('moonVisText').innerHTML = 'Show moon visibility on Light Level bar';
document.getElementById('changeInMinutesText').innerHTML = 'Show change in minutes of daylight from previous day (in Light Level pane)';
document.getElementById('extendedHoursPhraseTitle').innerHTML = 'Generic Extended Hours Phrase';
document.getElementById('dstRadioText').innerHTML = 'Daylight Saving Time';
document.getElementById('summerRadioText').innerHTML = 'Summer Time';
document.getElementById('checkAutoText').innerHTML = 'Check automatically';
document.getElementById('swUpdateResult').innerHTML = "";
document.getElementById('swUpdateMessage').innerHTML = "";
enableAddButton();
if (window.widget)
setTimeout('widget.performTransition();', 0);
//backsideChanged = false;
document.removeEventListener("keypress", keyPressed, true);
document.getElementById('fliprollie').style.display = 'none';
event.stopPropagation();
event.preventDefault();
}
function rebuildMaintable()
{
// fix up widget
var lastSelected = null;
if (currentSelection != null)
lastSelected = currentSelection.placeTimeID;
setupMainTable (false);
if (lastSelected != null)
{
var count = placeTimes.length;
var found = false;
for (var index = 0; index < count; ++index)
{
if (placeTimes[index] == lastSelected)
{
found = true;
break;
}
}
if (!found)
{
// the item we have selected is gone. select the first one
clickonrowimp (document.getElementById('placesHeader').firstChild);
}
else
{
moveSelectionToPlaceID (lastSelected);
}
}
if (window.vtMain)
vtMain.savePlaceInfo(true);
updateNow();
}
function selectDone ()
{
var front = document.getElementById("front");
var back = document.getElementById("back");
if (window.widget)
widget.prepareForTransition("ToFront");
front.style.display="block";
back.style.display="none";
isShowingFront = true;
if (is1043orNewer)
needToCompleteTransition = true;
if (window.widget)
setTimeout ('widget.performTransition();', 0);
//we no longer use the backsideChanged variable.
//if (backsideChanged)
// rebuildMaintable()
setTimeout ('vtMain.refreshClockFace();', 0);
//see transitioncomplete.
//if (NOT 10.4.3 or newer)
if (!is1043orNewer) {
setTimeout("calcWidgetHeightAndResize();", 750); //vc14: 800
if (alertWasShowing)
showAlert();
}
//onshow();
//setTimeout("calcWidgetHeightAndResize();", 0);
//if (window.widget)
// setTimeout ('widget.performTransition();', 0);
/*
if (resizedWhenFlippedOver)
{
calcWidgetHeightAndResize();
resizedWhenFlippedOver = false;
}
*/
document.getElementById('swUpdateResult').innerHTML = "";
document.getElementById('swUpdateMessage').innerHTML = "";
document.addEventListener("keypress", keyPressed, true);
}
//pre-fetch image
//(new Image()).src = "Images/selection_1.png";
//(new Image()).src = "Images/selection_X.png";
//(new Image()).src = "Images/selection_N.png";
function moveSelectionToPlaceID (placeTimeID)
{
var index;
var offset = 0; //1
var count = placeTimes.length;
for (index=0; index < count; ++index)
{
if (placeTimes[index] == placeTimeID)
break;
}
if (index == count)
index = 0;
if (window.vtMain)
vtMain2.setSelectedRowForID(placeTimeID);
switch (index)
{
case 0:
selection.src = "Images/selection_1.png";
offset = -1;
break;
case count - 1:
selection.src = "Images/selection_N.png";
offset = 1;
break;
default:
selection.src = "Images/selection_X.png";
break;
}
//the top border is about 6 pixels
var offsetStr = (25*index + 6 + offset).toString();
//alert("(" + placeTimeID + " index = " + index + ") off = " + offset + " tot = " + offsetStr);
selection.style.top = offsetStr + "px";
selection.style.display = "block";
if (!showingInfo) {
showingInfo = true;
updateDisplayOptions();
}
updateInfo();
}
function clickonrowimp (row)
{
currentSelection = row;
moveSelectionToPlaceID (row.placeTimeID);
}
// No reason to get excited, the thief he kindly spoke
// There are many here among us who feel that life is but a joke
// But you and I, we've been through that, and this is not our fate
// So let us not talk falsely now, the hour is getting late
// - Bob Dylan
//pre-fetch image
(new Image()).src = "Images/borderBottomNoTabs.png";
function updateInfo()
{
//alert("js-updateInfo: showingInfo = " + showingInfo);
if (currentSelection == null)
//if (!showingInfo || currentSelection == null) //vc14
return;
var count = placeTimes.length;
var found = false;
for (var index = 0; index < count; ++index)
{
if (placeTimes[index] == currentSelection.placeTimeID)
{
found = true;
break;
}
}
//alert("js-updateInfo: index = " + index);
if (!found)
{
alert("js-updateInfo: !found");
document.getElementById("currentLight").innerText = "";
document.getElementById("daylightDuration").innerText = "";
}
else
{
//sun
//document.getElementById("currentLightTitle").innerText = vtPlace.infoStringForRow(19, index);
document.getElementById("currentLight").innerText = vtPlace.infoStringForRow(20, index);
//var earthLight = currentSelection.earthLight;
var earthLight = vtPlace.earthLightKindForRow(index);
//alert("updateInfo: earthLight = " + earthLight);
document.getElementById('lightDot').src = getEarthLightImage(earthLight);
var timeInfo = vtPlace.infoStringListForRow(0, index);
document.getElementById('timePt-Image').style.left = (timeInfo[3]).toString() + "px";
//
// update various times
//
updateVariousTimesForRow (index);
if (showMoonLine)
document.getElementById('daylight-Image').src = vtPlace.imagePathForRow(2, index);
else
document.getElementById('daylight-Image').src = vtPlace.imagePathForRow(1, index);
document.getElementById("daylightDuration").innerText = vtPlace.infoStringForRow(21, index);
var daylightDiv = document.getElementById("daylightDiv");
if (showChangeInMinutes) {
daylightDiv.setAttribute("style", "left: 32px;");
document.getElementById("changeInMinutes").innerText = vtPlace.infoStringForRow(22, index);
} else {
daylightDiv.setAttribute("style", "left: 62px;");
document.getElementById("changeInMinutes").innerText = "";
}
//time
//drawClockHands
if (earthLight == 1) {
document.getElementById('clockFace').src = "Images/clockFaceDay.png";
clockHandHours = clockHandHours1;
clockHandMinutes = clockHandMinutes1;
} else {
document.getElementById('clockFace').src = "Images/clockFaceNight.png";
clockHandHours = clockHandHours5;
clockHandMinutes = clockHandMinutes5;
}
if (earthLight == 2)
clockHandHours = clockHandHours2;
else if (earthLight == 3)
clockHandHours = clockHandHours3;
else if (earthLight == 4)
clockHandHours = clockHandHours4;
document.getElementById("localDate").innerText = vtPlace.infoStringForRow(7, index);
document.getElementById("relativeTime").innerText = vtPlace.infoStringForRow(10, index);
//document.getElementById("dayOfWeek").innerText = vtPlace.infoStringForRow(8, index);
var utcOffset = vtPlace.infoStringForRow(11, index);
var tzAbbr = vtPlace.infoStringForRow(12, index);
document.getElementById("utc_tzAbbr").innerText = tzAbbr + " / " + utcOffset;
document.getElementById("utcOffset").innerText = utcOffset;
document.getElementById("tzAbbr").innerText = tzAbbr;
var extendedHoursPhraseIdx = useDSTInsteadOfSummer ? 14 : 15;
document.getElementById("dst").innerText = vtPlace.infoStringForRow(extendedHoursPhraseIdx, index);
document.getElementById("season").innerText = vtPlace.infoStringForRow(18, index);
//moon
var phases = vtPlace.phaseInfoForRow(index);
var prevPhase = phases[0];
var curPhase = phases[1];
var nextPhase = phases[2];
//updatePrevNextPhase(true, prevPhase[0]);
//phase times
if (showAMPM) {
document.getElementById("prevPhaseTime").innerText = prevPhase[2][1];
//document.getElementById("curPhaseTime").innerText = "1:11 AM";
//document.getElementById("curPhaseTime").innerText = curPhase[2][1];
document.getElementById("nextPhaseTime").innerText = nextPhase[2][1];
} else {
document.getElementById("prevPhaseTime").innerText = prevPhase[2][0];
//document.getElementById("curPhaseTime").innerText = "1:11";
//document.getElementById("curPhaseTime").innerText = curPhase[2][0];
document.getElementById("nextPhaseTime").innerText = nextPhase[2][0];
}
document.getElementById("curPhaseTitle").innerText = curPhase[0][1];
//prev
document.getElementById("prevPhaseTitle").innerText = prevPhase[0][1];
document.getElementById("prevPhaseDate").innerText = prevPhase[1][0];
//updatePrevNextPhase(false, nextPhase[0]);
document.getElementById("nextPhaseTitle").innerText = nextPhase[0][1];
document.getElementById("nextPhaseDate").innerText = nextPhase[1][0];
document.getElementById('curPhaseDot').src = vtPlace.imagePathForRow(9, index);
document.getElementById('curPhase-Image').src = vtPlace.imagePathForRow(10, index);
document.getElementById('prevPhase-Image').src = vtPlace.imagePathForRow(11, index);
document.getElementById('nextPhase-Image').src = vtPlace.imagePathForRow(12, index);
}
}
// I am a child, I'll last a while
// You can't conceive of the pleasure in my smile
// - Neil Young
function clickonrow (event, row)
{
var oldSelection = currentSelection;
if (currentSelection != null && row == currentSelection)
{
document.getElementById("selection").style.display = "none";
currentSelection = null;
if (window.vtMain)
vtMain2.setSelectedRowForID("none");
if (window.widget)
setPreferenceForKey("none", selectionPrefKey);
setupInfoAnimation (true);
showingInfo = false;
}
else
{
clickonrowimp(row);
if (window.widget && oldSelection != currentSelection)
{
//write out the selection
if (window.vtMain)
vtMain2.setSelectedRowForID(row.placeTimeID);
setPreferenceForKey(row.placeTimeID, selectionPrefKey);
}
if (oldSelection == null)
{
showingInfo = true;
setupInfoAnimation (false);
}
}
}
function updateVariousTimesForRow (selectionIndex)
{
var phases = vtPlace.phaseInfoForRow(selectionIndex);
var prevPhase = phases[0];
var curPhase = phases[1];
var nextPhase = phases[2];
//times
if (showAMPM) {
document.getElementById("time03").innerText = "3a";
document.getElementById("time06").innerText = "6a";
document.getElementById("time09").innerText = "9a";
document.getElementById("time12").innerText = "12p";
document.getElementById("time15").innerText = "3p";
document.getElementById("time18").innerText = "6p";
document.getElementById("time21").innerText = "9p";
document.getElementById("prevPhaseTime").innerText = prevPhase[2][1];
//old:
//document.getElementById("curPhaseTime").innerText = "1:11 AM";
//document.getElementById("curPhaseTime").innerText = curPhase[2][1];
document.getElementById("nextPhaseTime").innerText = nextPhase[2][1];
} else {
document.getElementById("time03").innerText = "3";
document.getElementById("time06").innerText = "6";
document.getElementById("time09").innerText = "9";
document.getElementById("time12").innerText = "12";
document.getElementById("time15").innerText = "15";
document.getElementById("time18").innerText = "18";
document.getElementById("time21").innerText = "21";
document.getElementById("prevPhaseTime").innerText = prevPhase[2][0];
//old:
//document.getElementById("curPhaseTime").innerText = "1:11";
//document.getElementById("curPhaseTime").innerText = curPhase[2][0];
document.getElementById("nextPhaseTime").innerText = nextPhase[2][0];
}
// rise/set info
var ampmIndex = showAMPM ? 2 : 1;
var riseSetInfo = vtPlace.infoStringListForRow(1, selectionIndex);
//for (var index = 0; index < placeTimes.length; index++)
// alert(index + "riseSetInfo[index]" + riseSetInfo[index]);
var riseSetIndex;
for (riseSetIndex = 0; riseSetIndex < 4; riseSetIndex++) {
document.getElementById ('riseSetTitle'+riseSetIndex).innerText = riseSetInfo[riseSetIndex][0];
document.getElementById ('riseSetTime'+riseSetIndex).innerText = riseSetInfo[riseSetIndex][ampmIndex];
document.getElementById ('riseSetAMPM'+riseSetIndex).innerText = showAMPM ? riseSetInfo[riseSetIndex][3] : "";
}
// twilight info
var twilightInfo = vtPlace.infoStringListForRow(2, selectionIndex);
var twilightIndex;
for (twilightIndex = 0; twilightIndex < 6; twilightIndex++) {
//alert(twilightIndex + " twi: " + twilightInfo[twilightIndex]);
document.getElementById ('twilightTitle'+twilightIndex).innerText = twilightInfo[twilightIndex][0];
document.getElementById ('twilightTime'+twilightIndex).innerText = twilightInfo[twilightIndex][ampmIndex];
document.getElementById ('twilightAMPM'+twilightIndex).innerText = showAMPM ? twilightInfo[twilightIndex][3] : "";
var twilightColor;
switch (twilightInfo[twilightIndex][4]) {
case 1: //civil
twilightColor = "color:#fe8a37;";
break;
case 2: //nautical
twilightColor = "color:#10c7b7;";
break;
case 3: //astronomical
twilightColor = "color:#0000eb;";
break;
default: //default
twilightColor = "color:#fe8a37;";
}
document.getElementById('twilightDiv'+twilightIndex).setAttribute ("style", twilightColor);
}
}
function clickonTime (event, node)
{
//var row = node.parentNode;
//alert("clickonTime: row.placeTimeID = " + row.placeTimeID);
//alert("clickonTime: event = " + event);
//alert("clickonTime: window.event = " + window.event);
//if (event.altKey)
// alert ("clickonTime: option key is down");
//else
// alert ("clickonTime: option key is up");
showAMPM = !showAMPM;
var foundSelection = false;
var selectionIndex = 0;
var header = document.getElementById('placesHeader');
for (var index = 0; index < placeTimes.length; ++index)
{
var row = header.childNodes[index];
var savedEarthLight = row.earthLight;
var placeTimeID = placeTimes[index];
var time24Span = document.getElementById(placeTimeID+"_time24");
var time12Span = document.getElementById(placeTimeID+"_time12");
var timeAMPMSpan = document.getElementById(placeTimeID+"_timeAMPM");
var digTimeBackground = document[placeTimeID+"_digTimeBack"];
if (showAMPM) {
if (savedEarthLight == 1)
digTimeBackground.src = "Images/digTime12_1.png";
else
digTimeBackground.src = "Images/digTime12_5.png";
digTimeBackground.setAttribute("style", "left: 177px;");
time24Span.setAttribute ("style", "display:none;");
time12Span.setAttribute ("style", "display:inline-block;");
timeAMPMSpan.setAttribute ("style", "display:inline-block;");
} else {
if (savedEarthLight == 1)
digTimeBackground.src = "Images/digTime24_1.png";
else
digTimeBackground.src = "Images/digTime24_5.png";
digTimeBackground.setAttribute("style", "left: 195px;");
time24Span.setAttribute ("style", "display:inline-block;");
time12Span.setAttribute ("style", "display:none;");
timeAMPMSpan.setAttribute ("style", "display:none;");
}
//find index of selected row
if (currentSelection != null && placeTimes[index] == currentSelection.placeTimeID)
{
selectionIndex = index;
foundSelection = true;
}
}
// change sun and moon time formats
if (foundSelection) {
updateVariousTimesForRow (selectionIndex);
}
// set preference
if (window.widget)
setPreferenceForKey(showAMPM, showAMPMPrefKey);
//reset checkbox
document.getElementById('timeFormatCheckbox').checked = !showAMPM;
// stop proagation otherwise the clickonrow handler would be called
event.stopPropagation();
event.preventDefault();
}
// I'm just a simple guy, I live from day to day.
// A ray of sunshine melts my frown and blows my blues away,
// Bonham, Page, Plant
function clickonLightLevel(event)
{
showMoonLine = !showMoonLine;
updateInfo();
// set preference
if (window.widget)
setPreferenceForKey(showMoonLine, showMoonLinePrefKey);
//reset checkbox
document.getElementById('moonVisCheckbox').checked = showMoonLine;
}
function onshow ()
{
if (window.vtMain)
vtMain.onShow();
}
function onhide ()
{
if (window.vtMain)
vtMain.onHide();
}
function transitioncomplete ()
{
//after performTransition
if (isShowingFront && needToCompleteTransition)
{
needToCompleteTransition = false;
setTimeout("calcWidgetHeightAndResize();", 0);
if (alertWasShowing)
showAlert();
}
}
document.addEventListener("keypress", keyPressed, true);
function keyPressed(event)
{
//Exit this function if the info area is not showing or there is no selection.
if (!showingInfo || currentSelection == null)
return;
//The up and down arrow keys only function if the info area
// is showing and there is a valid selection.
var movedSelection = false;
var changedInfo = false;
var selection = currentSelection;
switch (event.charCode)
{
case 63232: // up
movedSelection = true;
selection = selection.previousSibling;
if (selection == null)
{
selection = document.getElementById('placesHeader').lastChild;
}
break;
case 63233: // down
movedSelection = true;
selection = selection.nextSibling;
if (selection == null)
{
selection = document.getElementById('placesHeader').firstChild;
}
break;
//case 63235: // right
//case 63234: // left
default:
movedSelection = false;
changedInfo = false;
break;
}
if (movedSelection || changedInfo)
{
if (movedSelection)
clickonrow (event, selection);
if (changedInfo)
updateInfo();
event.stopPropagation();
event.preventDefault();
}
}
function setupMainTable(addPlacesToBackside)
{
var count = placeTimes.length;
var container = document.getElementById('placesHeader');
removeAllChildren(container);
for (var index=0; index<count; ++index)
{
var row = createRow (index);
container.appendChild (row);
if (addPlacesToBackside)
addPlace (index);
}
//set the bottom of table to correct class
if (count < 2) count = 2;
document.getElementById('tableBottom').setAttribute ("class", (count%2) != 0 ? "tableBottomDark" : "tableBottomLight");
// fill in the backgorund
container = document.getElementById('tableContainer');
removeAllChildren(container);
count = count - 2;
var light = true;
for (var index = 0; index < count; ++index)
{
var div = document.createElement ('div');
div.setAttribute ("class", light ? "tableRowLight" : "tableRowDark");
container.appendChild (div);
light = !light;
}
}
function addClock(region, place)
{
var placeTimeID = null;
if (window.vtMain)
placeTimeID = vtPlace.addClock(region, place, sortByCountry);
if (placeTimeID != null)
placeTimes[placeTimes.length] = placeTimeID;
return placeTimeID;
}
var curRegionIndex = 4; //America, North
var curPlaceIndex = 23; //Cupertino (vc14: 20)
//var curRegionIndex = 1;
//var curPlaceIndex = 9;
function setupClocks()
{
// Add default clocks or get clocks from saved preferences.
var status = "widget failure";
if (window.vtMain)
status = vtPlace.infoString(0);
document.getElementById("version").innerText = status;
if (!validMode)
return validMode;
var savedPlaces;
if (window.vtMain)
savedPlaces = vtMain.readPlaceInfo();
else
savedPlaces = new Array();
var placeCount = savedPlaces.length;
if (placeCount > 0) {
for (var index = 0; index < placeCount; ++index)
{
placeTimes[placeTimes.length] = savedPlaces[index];
}
} else {
addClock(4, 23); //Cupertino (vc14: 20)
vtMain.savePlaceInfo(true);
//alert("js-setupClocks: savePlaceInfo");
}
return true;
}
var eulaKey = "eula_vc15";
function selectAgree()
{
document.getElementById('eulaDiv').setAttribute ("style", "display:none;");
document.getElementById('front').setAttribute ("style", "display:inline-block;");
setupWidget();
//Remember agreement (a global pref)
if (window.widget)
widget.setPreferenceForKey(true, eulaKey);
}
var widgetResizedForDialog = false;
var preDialogHeight;
function showDialog(showOKButton, showOtherButtons, messageText1, messageText2)
{
if (window.outerHeight < 245) {
preDialogHeight = window.outerHeight;
window.resizeTo (widgetWidth, 245);
widgetResizedForDialog = true;
}
var buttonAttr;
buttonAttr = showOKButton ? "display:block;" : "display:none;";
document.getElementById('dialogOKButton').setAttribute ("style", buttonAttr);
buttonAttr = showOtherButtons ? "display:block;" : "display:none;";
document.getElementById('dialogPurchaseButton').setAttribute ("style", buttonAttr);
buttonAttr = showOtherButtons ? "display:block;" : "display:none;";
document.getElementById('dialogWebSiteButton').setAttribute ("style", buttonAttr);
//alert("*** entered showDialog");
document.getElementById("dialogMessage1").innerText = messageText1;
document.getElementById("dialogMessage2").innerText = messageText2;
document.getElementById('dialogDivContainer').setAttribute ("style", "display:block;");
document.getElementById('overlay').setAttribute ("style", "display:block;");
//Make flip icon go away if it's visible.
//mouseexit(event);
}
function controlWidget()
{
//initialize widget plug-in
if (window.vtMain)
{
// the code is in control!
var pluginMode = vtMain.initPlugin(widget.identifier);
if (pluginMode == 0)
demoMode = false;
else if (pluginMode == 1)
demoMode = true;
else
validMode = false;
} else {
alert("controlWidget: vtMain NOT loaded");
}
if (demoMode) {
//check for eula
var agreedToEULA = false;
if (window.widget)
{
var eulaPrefString = widget.preferenceForKey(eulaKey);
agreedToEULA = eulaPrefString != null;
//alert("eulaPrefString = " + eulaPrefString);
//if (eulaPrefString && eulaPrefString.length > 0)
// agreedToEULA = eulaPrefString == eulaValue;
}
if (agreedToEULA) {
setupWidget();
} else {
document.getElementById('front').setAttribute ("style", "display:none;");
document.getElementById('eulaDiv').setAttribute ("style", "display:inline-block;");
//Agree button
var agreeButton = document.getElementById('agreeButton');
createGenericButton (agreeButton, 'Agree', selectAgree, 67);
}
} else {
//set up widget!
document.getElementById('eulaDiv').setAttribute ("style", "display:none;");
document.getElementById('front').setAttribute ("style", "display:inline-block;");
setupWidget();
//Remember agreement (a global pref)
if (window.widget)
widget.setPreferenceForKey(true, eulaKey);
}
}
function getPrefs()
{
showAMPM = getPreferenceForKey(showAMPMPrefKey, false);
if (showAMPM == null) {
if (window.vtMain)
showAMPM = vtMain2.getShowAMPMSystem();
else
showAMPM = true;
}
showLeadingZeros = getPreferenceForKey(showLeadingZerosPrefKey, false);
if (showLeadingZeros == null) {
if (window.vtMain)
showLeadingZeros = vtMain.useLeadingZeros();
else
showLeadingZeros = false;
} else {
if (window.vtMain)
vtMain.setUseLeadingZeros(showLeadingZeros);
}
hideSeconds = getPreferenceForKey(hideSecondsPrefKey, false);
if (hideSeconds == null) {
hideSeconds = true;
} else {
if (window.vtMain)
vtMain.setHideSeconds(hideSeconds);
}
var localTimeSeconds = document.getElementById('localTimeSeconds');
if (hideSeconds)
localTimeSeconds.setAttribute ("style", "display:none;");
else
localTimeSeconds.setAttribute ("style", "display:inline-block;");
useDSTInsteadOfSummer = getPreferenceForKey(useDSTInsteadOfSummerPrefKey, false);
if (useDSTInsteadOfSummer == null) {
if (window.vtMain)
useDSTInsteadOfSummer = vtMain2.getShowAMPMSystem();
else
useDSTInsteadOfSummer = true;
}
showMoonLine = getPreferenceForKey(showMoonLinePrefKey, false);
if (showMoonLine == null)
showMoonLine = true;
showChangeInMinutes = getPreferenceForKey(showChangeInMinutesPrefKey, false);
if (showChangeInMinutes == null)
showChangeInMinutes = true;
sortByCountry = getPreferenceForKey(sortByCountryPrefKey, false);
if (sortByCountry == null)
sortByCountry = false;
//reset checkboxes
document.getElementById('sortCheckbox').checked = sortByCountry;
document.getElementById('timeFormatCheckbox').checked = !showAMPM;
document.getElementById('leadingZerosCheckbox').checked = showLeadingZeros;
document.getElementById('hideSecondsCheckbox').checked = hideSeconds;
document.getElementById('moonVisCheckbox').checked = showMoonLine;
document.getElementById('changeInMinutesCheckbox').checked = showChangeInMinutes;
document.getElementById('dstRadio').checked = useDSTInsteadOfSummer;
document.getElementById('summerRadio').checked = !useDSTInsteadOfSummer;
//curRegionIndex is initialized to 1 (North America)
var regionIndexStr = getPreferenceForKey(regionPrefKey, false);
if (regionIndexStr != null)
curRegionIndex = parseInt(regionIndexStr);
//curPlaceIndex is initialized to 23 (Cupertino)
var placeIndexStr = getPreferenceForKey(placePrefKey, false);
if (placeIndexStr != null)
curPlaceIndex = parseInt(placeIndexStr);
populateRegionSelect();
document.getElementById ('region-dropDownMenu').options[curRegionIndex].selected = true;
popuplateCitySelect();
document.getElementById ('city-dropDownMenu').options[curPlaceIndex].selected = true;
}
function setupWidget()
{
var selectedPlaceTimeID = null;
if (window.widget)
{
//populateBacksideSelect();
//document.getElementById ('content-backsideMenu').options[curBacksideItem].selected = true;
is1043orNewer = vtMain2.checkFor1043orNewer();
//These two elements must be set before setupClocks(). This is mainly
// for the special case of having a newer version then rebooting and
// not having a network connection.
document.getElementById('newVersionText').innerHTML = "";
document.getElementById('alertMessage').innerHTML = "";
var success = setupClocks();
if (!success) {
alert("setupClocks failed");
return;
}
try {
selectedPlaceTimeID = getPreferenceForKey(selectionPrefKey, false);
getPrefs();
setupInfoDivs();
}
catch(ex)
{
alert("starup error");
}
}
// add all of our places to the widget
setupMainTable (true);
var header = document.getElementById('placesHeader');
currentSelection = header.firstChild;
if (selectedPlaceTimeID != null)
{
if (selectedPlaceTimeID == "none")
{
document.getElementById("selection").style.display = "none";
currentSelection = null;
showingInfo = false;
document.getElementById('infoAreaContainer').style.height = "0";
}
else
{
for (var child = header.firstChild; child != null; child = child.nextSibling)
{
if (child.placeTimeID == selectedPlaceTimeID)
{
// no need to do anything if the first item is the one selected.
if (currentSelection != child)
{
clickonrowimp (child);
}
}
}
}
}
//adjust position of selected state.
if (currentSelection == header.firstChild)
clickonrowimp (currentSelection);
if (showingInfo) {
//Important
updateDisplayOptions();
document.getElementById('divSunButton').setAttribute ("style", "display:inline-block;");
document.getElementById('divRiseSetButton').setAttribute ("style", "display:inline-block;");
document.getElementById('divMoonButton').setAttribute ("style", "display:inline-block;");
document.getElementById('divTimeButton').setAttribute ("style", "display:inline-block;");
document.getElementById('footer').setAttribute ("style", "background-image:url(Images/borderBottom.png);");
}
else {
document.getElementById('divSunButton').setAttribute ("style", "display:none;");
document.getElementById('divRiseSetButton').setAttribute ("style", "display:none;");
document.getElementById('divMoonButton').setAttribute ("style", "display:none;");
document.getElementById('divTimeButton').setAttribute ("style", "display:none;");
document.getElementById('footer').setAttribute ("style", "background-image:url(Images/borderBottomNoTabs.png);");
}
// backside strings
document.getElementById('citiesLabel').innerText = "Cities/Places:";
//document.getElementById('demoText').innerHTML = "Demo";
//document.getElementById("wTitle").innerText = "VelaClock";
document.getElementById("creators").innerText = "Creators";
document.getElementById("creator1").innerText = "Jennifer Goshay";
document.getElementById("creator2").innerText = "Chuck Soper";
document.getElementById("creator3").innerText = "Klaus Strelau";
document.getElementById("role1").innerText = "Artist:";
document.getElementById("role2").innerText = "Developers:";
document.getElementById("role3").innerText = "";
document.getElementById("credits").innerText = "Acknowledgments";
document.getElementById("source1").innerText = "Astronomy on the Personal Computer";
document.getElementById("source1TitleA").innerText = "Authors:";
document.getElementById("source1DescA").innerText = "Oliver Montenbruck Thomas Pfleger";
document.getElementById("source1TitleB").innerText = "Publisher:";
document.getElementById("source1DescB").innerText = "Springer Verlag";
document.getElementById("source1Desc").innerText = 'Thorough introduction to the computation of celestial mechanics.';
document.getElementById("source1Perm").innerText = "Written permission was obtained from both authors and the publisher.";
document.getElementById("source2").innerText = "Photo © UC Regents/Lick Observatory";
document.getElementById("source2Desc").innerText = "Full moon photo was taken in the late 1930s with a 36-inch refracting telescope originally built in 1888.";
document.getElementById("source2Link").innerText = "www.ucolick.org";
document.getElementById("source2Perm").innerText = "Written permission was obtained from Lick Observatory. Unauthorized use prohibited.";
document.getElementById("source3").innerText = "tz database";
document.getElementById("source3Desc").innerText = "Public-domain time zone database.";
document.getElementById("productName").innerText = "VelaClock";
document.getElementById("productInfo").innerText = "VelaClock Web Page";
document.getElementById("companyName").innerText = "Copyright © 2005-2006 Vela Design Group";
document.getElementById("copyright").innerText = "All Rights Reserved";
//document.getElementById("regTitle").innerText = "Not Registered";
//Add place button
var addButton = document.getElementById('addPlace');
createGenericButton (addButton, getLocalizedString('Add'), addButtonClicked, 67);
enableAddButton();
document.getElementById("addHint").innerText = "";
//moveUp button
var moveUpButton = document.getElementById('moveUp');
createGenericButton (moveUpButton, getLocalizedString('↑'), moveUpClicked, 20); //‚Üë
genericButtonSetEnabled (moveUpButton, false);
//moveDown button
var moveDownButton = document.getElementById('moveDown');
createGenericButton (moveDownButton, getLocalizedString('↓'), moveDownClicked, 20); //‚Üì
genericButtonSetEnabled (moveDownButton, false);
//Remove place button
var removeButton = document.getElementById('removePlace');
createGenericButton (removeButton, getLocalizedString('Remove'), removeButtonClicked);
genericButtonSetEnabled (removeButton, false);
//Other button (for 'Purchase' or 'Send Feedback')
var otherButton = document.getElementById('otherButton');
var buttonTitle = demoMode ? 'Purchase or Register' : 'Send Feedback'; //use getLocalizedString
createGenericButton (otherButton, buttonTitle, purchaseButtonClicked);
genericButtonSetEnabled (otherButton, true);
//Done button
var doneButton = document.getElementById('doneButton');
createGenericButton (doneButton, getLocalizedString('Done'), selectDone, 67);
//
// Demo Dialog controls
//
document.getElementById("dialogTitle").innerText = "VelaClock Demo";
var dialogOKButton = document.getElementById('dialogOKButton');
createButton (dialogOKButton, getLocalizedString('OK'), clickOnOKDialogButton, 66);
var dialogPurchaseButton = document.getElementById('dialogPurchaseButton');
createButton (dialogPurchaseButton, getLocalizedString('Purchase or Register'), launchPurchaseApp, 136);
var dialogWebSiteButton = document.getElementById('dialogWebSiteButton');
createButton (dialogWebSiteButton, getLocalizedString('Visit Web Site'), clickLogo, 136);
onshow();
//CFS
updateNow(); //calls updateInfo
//if (window.widget && !showingInfo)
//if (window.widget && (placeTimes.length != 6 || !showingInfo))
//{
// window.resizeTo (widgetWidth, calculateWidgetHeight());
//}
setTimeout("calcWidgetHeightAndResize();", 0);
//This line was added to redraw the clock hands after a reload (cmd-R).
if (window.vtMain)
setTimeout ('vtMain.refreshClockFace();', 0);
}
// add various callbacks
if (window.widget)
{
widget.onhide = onhide;
widget.onshow = onshow;
widget.onremove = onremove;
widget.ontransitioncomplete = transitioncomplete;
}
/*
var contentList = [
{menuItem:'Credits'},
{menuItem:'Settings'},
{menuItem:'Registration'}
];
function populateBacksideSelect()
{
//alert("populateBacksideSelect: entering");
var select = document.getElementById ('content-backsideMenu');
//if (select.hasChildNodes())
// return;
var menuItemCnt = contentList.length;
for (var index = 0; index < menuItemCnt; ++index)
{
var element = document.createElement("option");
element.innerText = contentList[index].menuItem;
select.appendChild (element);
}
}
*/
function showBackCitiesDiv()
{
if (curBacksideItem != 0) {
curBacksideItem = 0;
changeBacksideContent();
//document.getElementById ('content-backsideMenu').options[curBacksideItem].selected = true;
}
}
function showBackRegDiv()
{
if (curBacksideItem != 1) {
curBacksideItem = 1;
changeBacksideContent();
//document.getElementById ('content-backsideMenu').options[curBacksideItem].selected = true;
}
}
function showBackHelpDiv()
{
if (curBacksideItem != 2) {
curBacksideItem = 2;
changeBacksideContent();
//document.getElementById ('content-backsideMenu').options[curBacksideItem].selected = true;
}
}
function showBackCreditsDiv()
{
if (curBacksideItem != 3) {
curBacksideItem = 3;
changeBacksideContent();
//document.getElementById ('content-backsideMenu').options[curBacksideItem].selected = true;
}
}
function changeBacksideContent()
{
if (curBacksideItem == 0) { //Cities
document.getElementById('citiesDiv').setAttribute ("style", "display:inline-block;");
document.getElementById('settingsDiv').setAttribute ("style", "display:none;");
document.getElementById('helpDiv').setAttribute ("style", "display:none;");
document.getElementById('creditsDiv').setAttribute ("style", "display:none;");
document.getElementById('backTab1').src = "Images/backTab1.png";
document.getElementById('backTab2').src = "Images/backTab2Un.png";
document.getElementById('backTab3').src = "Images/backTab3Un.png";
document.getElementById('backTab4').src = "Images/backTab4Un.png";
}
else if (curBacksideItem == 1) { //Settings
document.getElementById('citiesDiv').setAttribute ("style", "display:none;");
document.getElementById('settingsDiv').setAttribute ("style", "display:inline-block;");
document.getElementById('helpDiv').setAttribute ("style", "display:none;");
document.getElementById('creditsDiv').setAttribute ("style", "display:none;");
document.getElementById('backTab1').src = "Images/backTab1Un.png";
document.getElementById('backTab2').src = "Images/backTab2.png";
document.getElementById('backTab3').src = "Images/backTab3Un.png";
document.getElementById('backTab4').src = "Images/backTab4Un.png";
}
else if (curBacksideItem == 2) { //Help
document.getElementById('citiesDiv').setAttribute ("style", "display:none;");
document.getElementById('settingsDiv').setAttribute ("style", "display:none;");
document.getElementById('helpDiv').setAttribute ("style", "display:inline-block;");
document.getElementById('creditsDiv').setAttribute ("style", "display:none;");
document.getElementById('backTab1').src = "Images/backTab1Un.png";
document.getElementById('backTab2').src = "Images/backTab2Un.png";
document.getElementById('backTab3').src = "Images/backTab3.png";
document.getElementById('backTab4').src = "Images/backTab4Un.png";
}
else { //Credits
document.getElementById('citiesDiv').setAttribute ("style", "display:none;");
document.getElementById('settingsDiv').setAttribute ("style", "display:none;");
document.getElementById('helpDiv').setAttribute ("style", "display:none;");
document.getElementById('creditsDiv').setAttribute ("style", "display:inline-block;");
document.getElementById('backTab1').src = "Images/backTab1Un.png";
document.getElementById('backTab2').src = "Images/backTab2Un.png";
document.getElementById('backTab3').src = "Images/backTab3Un.png";
document.getElementById('backTab4').src = "Images/backTab4.png";
}
}
function backsideContentChanged (select)
{
if (curBacksideItem != select.selectedIndex)
{
curBacksideItem = select.selectedIndex;
changeBacksideContent();
}
}
function populateRegionSelect()
{
//alert("populateRegionSelect: entering");
if (window.vtMain) {
var regionList = vtMain2.regionList();
var select = document.getElementById ('region-dropDownMenu');
//if (select.hasChildNodes())
// return;
var regionCnt = regionList.length;
for (var index = 0; index < regionCnt; ++index)
{
var element = document.createElement("option");
element.innerText = regionList[index];
select.appendChild (element);
}
}
}
function popuplateCitySelect()
{
if (window.vtMain) {
var placeList = vtMain2.placeListForRegion(curRegionIndex, sortByCountry);
var select = document.getElementById ('city-dropDownMenu');
while (select.hasChildNodes())
select.removeChild(select.firstChild);
var placeCnt = placeList.length;
for (var index = 0; index < placeCnt; ++index)
{
var element = document.createElement("option");
element.innerText = placeList[index];
//if (index == 1)
// element.innerText = placeList[index] + " [$]";
//else
// element.innerText = placeList[index];
select.appendChild (element);
}
}
}
function enableAddButton(notAvailable)
{
var addButton = document.getElementById('addPlace');
if (placeTimes.length == maxItems) {
genericButtonSetEnabled (addButton, false);
document.getElementById("addHint").innerText = "A maximum of 24 places may be added.";
return;
}
var placeAlreadyExists = true;
var addHintText = "";
if (window.vtMain) {
var addInfoArray = vtPlace.addInfo(curRegionIndex, curPlaceIndex, sortByCountry);
placeAlreadyExists = addInfoArray[0];
addHintText = addInfoArray[1];
}
document.getElementById("addHint").innerText = addHintText;
genericButtonSetEnabled (addButton, !placeAlreadyExists);
}
function regionChanged (select)
{
//alert("regionChanged: entering");
if (curRegionIndex != select.selectedIndex)
{
curRegionIndex = select.selectedIndex;
popuplateCitySelect();
curPlaceIndex = 0;
document.getElementById ('city-dropDownMenu').options[curPlaceIndex].selected = true;
enableAddButton();
if (window.widget) {
setPreferenceForKey(curRegionIndex.toString(), regionPrefKey);
setPreferenceForKey(curPlaceIndex.toString(), placePrefKey);
}
}
}
function cityChanged (select)
{
//alert("cityChanged: entering");
if (curPlaceIndex != select.selectedIndex)
{
curPlaceIndex = select.selectedIndex;
enableAddButton();
if (window.widget) {
setPreferenceForKey(curRegionIndex.toString(), regionPrefKey);
setPreferenceForKey(curPlaceIndex.toString(), placePrefKey);
}
}
}
var selectedRow=null;
function clickonbackrow(event, row)
{
var moveUpButton = document.getElementById('moveUp');
var moveDownButton = document.getElementById('moveDown');
if (placeTimes.length > 1)
genericButtonSetEnabled (document.getElementById('removePlace'), true);
if (selectedRow == row && event != null && event.metaKey)
{
row.setAttribute("class", "row");
selectedRow = null;
genericButtonSetEnabled (moveUpButton, false);
genericButtonSetEnabled (moveDownButton, false);
genericButtonSetEnabled (document.getElementById('removePlace'), false);
}
else if (selectedRow != row)
{
if (selectedRow != null)
selectedRow.setAttribute("class", "row");
selectedRow = row;
var index;
var found = false;
var count = placeTimes.length;
for (index = 0; index < count; ++index)
{
if (placeTimes[index] == row.placeTimeID)
{
found = true;
break;
}
}
genericButtonSetEnabled (moveUpButton, index != 0);
genericButtonSetEnabled (moveDownButton, index != count-1);
//alert("backRow: index = " + index + " placeTimeID = " + row.placeTimeID);
row.setAttribute ("class", "row select");
}
if (event)
{
event.stopPropagation();
event.preventDefault();
}
}
var lastValidPlaceTimeID = null;
function placeAlreadyInSet(placeTimeID)
{
var count = placeTimes.length;
for (var index = 0; index < count; ++index)
{
if (placeTimes[index] == placeTimeID)
return index;
}
return -1;
}
function addOrSelectItem ()
{
var index = placeAlreadyInSet(lastValidPlaceTimeID);
if (index < 0)
{
// make sure we have the correct number of items
if (placeTimes.length < maxItems)
{
index = placeTimes.length;
var placeTimeID = addClock(curRegionIndex, curPlaceIndex);
if (placeTimeID != null) {
if (window.vtMain)
vtMain.savePlaceInfo(true);
var row = addPlace (index);
//backsideChanged = true;
clickonbackrow (null, row);
//var innerList = document.getElementById('inner-list');
//innerList.scrollIntoView(false);
if (placeTimes.length == maxItems)
enableAddButton();
rebuildMaintable();
}
}
}
else
{
// select the item that is already there.
var row = document.getElementById('inner-list').firstChild;
for (var i = 0; index < index; ++index)
row = row.nextSibling;
if (row != null) // just to be safe, should never happen
{
clickonbackrow (null, row);
}
}
}
function findIndexOfChild (child)
{
var node = child.parentNode;
var index = 0;
for (node = node.firstChild; node != null; node = node.nextSibling, ++index)
{
if (node == child)
return index;
}
return -1;
}
function removeAllChildren (parent)
{
while (parent.hasChildNodes())
parent.removeChild(parent.firstChild);
}
function addButtonClicked ()
{
lastValidPlaceTimeID = vtPlace.generatePlaceTimeID(curRegionIndex, curPlaceIndex, sortByCountry);
//alert("addButtonClicked: lastValidPlaceTimeID = " + lastValidPlaceTimeID);
//CFS: call and fix this function!
addOrSelectItem();
//scroll to bottom of list
if (placeTimes.length > 4) {
var list = document.getElementById('list');
list.scrollTop = 17 * (placeTimes.length - 4);
}
enableAddButton();
}
function moveUpClicked ()
{
if (selectedRow != null)
{
var index = findIndexOfChild (selectedRow);
if (index <= 1)
genericButtonSetEnabled (document.getElementById('moveUp'), false);
genericButtonSetEnabled (document.getElementById('moveDown'), true);
var parentNode = selectedRow.parentNode;
var prevSib = selectedRow.previousSibling;
parentNode.insertBefore(selectedRow, prevSib);
var idToMove = placeTimes[index];
placeTimes[index] = placeTimes[index-1];
placeTimes[index-1] = idToMove;
//reorder placeTimes array
vtPlace.exchangePlaceTimes(index, index-1);
//auto-scroll (disabled for now)
//var list = document.getElementById('list');
//var topOfRow = (index-1) * 17;
//Is row is above visible rows?
//if (topOfRow < list.scrollTop)
// list.scrollTop = topOfRow;
//Is row is below visible rows?
//else if (topOfRow > list.scrollTop + (4*17))
// list.scrollTop = list.scrollTop + (3*17);
//backsideChanged = true;
rebuildMaintable();
}
}
function moveDownClicked ()
{
if (selectedRow != null)
{
var index = findIndexOfChild (selectedRow);
if (index >= (placeTimes.length-2))
genericButtonSetEnabled (document.getElementById('moveDown'), false);
genericButtonSetEnabled (document.getElementById('moveUp'), true);
var parentNode = selectedRow.parentNode;
var nextSib = selectedRow.nextSibling;
parentNode.insertBefore(nextSib, selectedRow);
var idToMove = placeTimes[index];
placeTimes[index] = placeTimes[index+1];
placeTimes[index+1] = idToMove;
//reorder placeTimes array
vtPlace.exchangePlaceTimes(index, index+1);
//auto-scroll (not implemented)
//var list = document.getElementById('list');
//backsideChanged = true;
rebuildMaintable();
}
}
function removeButtonClicked ()
{
if (selectedRow != null)
{
var index = findIndexOfChild (selectedRow);
var parentNode = selectedRow.parentNode;
placeTimes.splice (index, 1);
if (window.vtMain) {
vtPlace.removePlaceTime(index);
vtMain.savePlaceInfo(true);
//alert("js-removeButtonClicked: savePlaceInfo");
}
parentNode.removeChild(selectedRow);
selectedRow = null;
if (placeTimes.length > 1)
{
if (index >= placeTimes.length)
index = placeTimes.length-1;
var nextSelection = parentNode.firstChild;
for (var index=0; index<index;++index)
nextSelection = nextSelection.nextSibling;
if (nextSelection != null) {
clickonbackrow (null, nextSelection);
genericButtonSetEnabled (document.getElementById('removePlace'), true);
}
}
else
{
genericButtonSetEnabled (document.getElementById('removePlace'), false);
}
enableAddButton();
//backsideChanged = true;
rebuildMaintable();
}
}
function setDemoMode(mode)
{
//alert("setDemoMode");
demoMode = mode;
if (!demoMode) {
//show 'registered' dialog
document.getElementById("dialogTitle").innerText = "Registration";
showDialog(true, false, "VelaClock is registered.", "Thank you.");
//update version to show 'registered'
document.getElementById("version").innerText = vtPlace.infoString(0);
//update the Add button
enableAddButton();
otherButton = document.getElementById('otherButton');
while (otherButton.hasChildNodes())
otherButton.removeChild(otherButton.firstChild);
createGenericButton (otherButton, 'Send Feedback', purchaseButtonClicked);
genericButtonSetEnabled (otherButton, true);
//updateNow(); //not necessary
}
}
function clickonSort(event)
{
sortByCountry = !sortByCountry;
popuplateCitySelect();
curPlaceIndex = vtMain2.mapPlaceIndex(curRegionIndex, curPlaceIndex, !sortByCountry);
//curPlaceIndex = 0; //map placeIndex
document.getElementById ('city-dropDownMenu').options[curPlaceIndex].selected = true;
enableAddButton();
//clickonSort is called when either the checkbox or checkbox title
// (the text next to the checkbox) is clicked.
var sortCheckbox = document.getElementById('sortCheckbox');
//tagName differentiates the checkbox and the checkbox title.
if (event.srcElement.tagName != "INPUT")
sortCheckbox.checked = !sortCheckbox.checked;
// set preference
if (window.widget) {
setPreferenceForKey(sortByCountry, sortByCountryPrefKey);
setPreferenceForKey(curPlaceIndex.toString(), placePrefKey);
}
}
function clickon24Hour(event)
{
showAMPM = !showAMPM;
//clickon24Hour is called when either the checkbox or checkbox title
// (the text next to the checkbox) is clicked.
var timeFormatCheckbox = document.getElementById('timeFormatCheckbox');
// timeFormatCheckbox.checked = showAMPM;
//tagName differentiates the checkbox and the checkbox title.
if (event.srcElement.tagName != "INPUT")
timeFormatCheckbox.checked = !timeFormatCheckbox.checked;
// set preference
if (window.widget)
setPreferenceForKey(showAMPM, showAMPMPrefKey);
//backsideChanged = true;
rebuildMaintable();
}
function clickonLeadingZeros(event)
{
showLeadingZeros = !showLeadingZeros;
//clickonLeadingZeros is called when either the checkbox or checkbox title
// (the text next to the checkbox) is clicked.
var leadingZerosCheckbox = document.getElementById('leadingZerosCheckbox');
//tagName differentiates the checkbox and the checkbox title.
if (event.srcElement.tagName != "INPUT")
leadingZerosCheckbox.checked = !leadingZerosCheckbox.checked;
if (window.vtMain)
vtMain.setUseLeadingZeros(showLeadingZeros);
// set preference
if (window.widget)
setPreferenceForKey(showLeadingZeros, showLeadingZerosPrefKey);
//backsideChanged = true;
rebuildMaintable();
}
function clickonHideSeconds(event)
{
hideSeconds = !hideSeconds;
var localTimeSeconds = document.getElementById('localTimeSeconds');
if (hideSeconds)
localTimeSeconds.setAttribute ("style", "display:none;");
else
localTimeSeconds.setAttribute ("style", "display:inline-block;");
//clickonLeadingZeros is called when either the checkbox or checkbox title
// (the text next to the checkbox) is clicked.
var hideSecondsCheckbox = document.getElementById('hideSecondsCheckbox');
//tagName differentiates the checkbox and the checkbox title.
if (event.srcElement.tagName != "INPUT")
hideSecondsCheckbox.checked = !hideSecondsCheckbox.checked;
if (window.vtMain)
vtMain.setHideSeconds(hideSeconds);
// set preference
if (window.widget)
setPreferenceForKey(hideSeconds, hideSecondsPrefKey);
//backsideChanged = true;
// rebuildMaintable();
}
function clickonDSTRadio(event)
{
useDSTInsteadOfSummer = !useDSTInsteadOfSummer;
document.getElementById('dstRadio').checked = true;
document.getElementById('summerRadio').checked = false;
// set preference
if (window.widget)
setPreferenceForKey(useDSTInsteadOfSummer, useDSTInsteadOfSummerPrefKey);
}
function clickonSummerRadio(event)
{
useDSTInsteadOfSummer = !useDSTInsteadOfSummer;
document.getElementById('dstRadio').checked = false;
document.getElementById('summerRadio').checked = true;
// set preference
if (window.widget)
setPreferenceForKey(useDSTInsteadOfSummer, useDSTInsteadOfSummerPrefKey);
}
function clickonMoonVis(event)
{
showMoonLine = !showMoonLine;
//clickonMoonVis is called when either the checkbox or checkbox title
// (the text next to the checkbox) is clicked.
var moonVisCheckbox = document.getElementById('moonVisCheckbox');
//tagName differentiates the checkbox and the checkbox title.
if (event.srcElement.tagName != "INPUT")
moonVisCheckbox.checked = !moonVisCheckbox.checked;
// set preference
if (window.widget)
setPreferenceForKey(showMoonLine, showMoonLinePrefKey);
//backsideChanged = true;
rebuildMaintable();
//if (window.vtMain)
// vtMain.24Hour(timeFormatCheckbox.checked);
}
function clickonChangeInMinutes(event)
{
showChangeInMinutes = !showChangeInMinutes;
//clickonMoonVis is called when either the checkbox or checkbox title
// (the text next to the checkbox) is clicked.
var changeInMinutesCheckbox = document.getElementById('changeInMinutesCheckbox');
//tagName differentiates the checkbox and the checkbox title.
if (event.srcElement.tagName != "INPUT")
changeInMinutesCheckbox.checked = !changeInMinutesCheckbox.checked;
// set preference
if (window.widget)
setPreferenceForKey(showChangeInMinutes, showChangeInMinutesPrefKey);
//backsideChanged = true;
rebuildMaintable();
}
function clickonCheckAuto(event)
{
//clickonCheckAuto is called when either the checkbox or checkbox title
// (the text next to the checkbox) is clicked.
var checkAutoCheckbox = document.getElementById('checkAutoCheckbox');
//tagName differentiates the checkbox and the checkbox title.
if (event.srcElement.tagName != "INPUT")
checkAutoCheckbox.checked = !checkAutoCheckbox.checked;
if (window.vtMain)
vtMain.checkAuto(checkAutoCheckbox.checked);
}
function clickonCheckNow(event)
{
if (window.vtMain) {
var checkNowButton = document.getElementById('checkNowButton');
checkNowButton.setAttribute("disabled", "disabled");
vtMain.checkNow();
}
}
var updateLink = null;
function updateNewVersionText(message, newUpdateLink)
{
document.getElementById('newVersionText').innerHTML = message;
updateLink = newUpdateLink;
document.getElementById('alertMessage').innerHTML = message;
if (message.length > 0) {
showAlert();
} else {
hideAlert();
alertWasShowing = false;
}
}
function updateCheckNowMessage(result, message)
{
//alert("updateCheckNowMessage = " + message);
document.getElementById('swUpdateResult').innerHTML = result;
document.getElementById('swUpdateMessage').innerHTML = message;
var checkNowButton = document.getElementById('checkNowButton');
checkNowButton.removeAttribute("disabled");
}
var alertIsShowing = false;
function showAlert()
{
document.getElementById('alertDiv').setAttribute ("style", "display:inline-block;");
alertIsShowing = true;
}
function hideAlert()
{
document.getElementById('alertDiv').setAttribute ("style", "display:none;");
alertIsShowing = false;
}
function clickOnOKDialogButton()
{
//make dialog go away
document.getElementById('dialogDivContainer').setAttribute ("style", "display:none;");
document.getElementById('overlay').setAttribute ("style", "display:none;");
//resize widget, if necessary
if (widgetResizedForDialog) {
window.resizeTo (widgetWidth, preDialogHeight);
widgetResizedForDialog = false;
}
}
function launchPurchaseApp()
{
if (event.shiftKey) {
//Use widget.openApplication() if shift key held down.
widget.openApplication('com.veladg.VelaReg');
} else {
var documentPath = document.URL;
var pathComponents = documentPath.split("/");
var docName = pathComponents[pathComponents.length - 1];
var velaRegPath = documentPath.substring(0, (documentPath.length - docName.length)) + "VelaReg.app";
//alert("velaRegPath = " + velaRegPath);
widget.openURL(velaRegPath);
//widget.system("/usr/bin/open " + velaRegPath, null);
}
//Command key: event.ctrlKey
//option key: event.altKey
}
function purchaseButtonClicked()
{
//alert("purchaseButtonClicked");
if (demoMode) {
launchPurchaseApp();
} else {
widget.openURL("http://www.veladg.com/feedback.html?p=VelaClock");
}
}
function addPlace (index)
{
var innerList = document.getElementById('inner-list');
var row = document.createElement('div');
row.setAttribute("class", "row");
row.setAttribute("onclick", "clickonbackrow(event, this);");
var span = document.createElement('span');
span.setAttribute ("class", "placesColumn");
if (index < 0) {
span.innerText = "unknown";
} else {
span.innerText = vtPlace.infoStringForRow(0, index);
row.setAttribute ("placeTimeID", placeTimes[index]);
}
row.appendChild(span);
innerList.appendChild(row);
return row;
}
function clickLickObs(event)
{
if (widget)
widget.openURL("http://www.ucolick.org/");
}
function clickLogo()
{
if (widget) {
if (demoMode)
widget.openURL("http://www.veladg.com/velaclockDemo.html");
else
widget.openURL("http://www.veladg.com/velaclock.html");
}
}
function clickNewVersion(event)
{
if (widget && updateLink != null)
widget.openURL(updateLink);
}
function calcWidgetHeightAndResize()
{
var height = calculateWidgetHeight();
if (window.widget)
window.resizeTo(widgetWidth, height);
}
function calculateWidgetHeight()
{
var height = 31 + // 34 row 1 (table top)
28 + // 29 row N (table bottom)
30; // 24 28 35 footer
var numberOfRows = placeTimes.length - 2;
if (numberOfRows > 0)
height += (numberOfRows * 25); // 25 row height
var infoHeight = 0; //this used to be global and set to 99.
if (showingInfo) {
infoHeight += infoAreaTopHeight; //infoBackTop.png
infoHeight += infoAreaBottomHeight; //infoBackBottom.png
infoHeight += 10; //5 taller borderBottom (shorter borderBottomNoTabs)
//height += infoHeight;
var index;
var count = infoDivs.length;
for (index = 0; index < count; ++index)
{
var subInfoDiv = infoDivs[index];
if (subInfoDiv.showing) {
infoHeight += subInfoDiv.fullHeight ? subInfoDiv.maxHeight : subInfoDiv.minHeight;
infoHeight += infoDivBottomHeight; //used to assign to height
}
//Or, just calculate the DIV height?
//var divElement = document.getElementById(infoDivs[index].id);
//infoHeight += parseInt(divElement.style.height, 10);
}
height += infoHeight;
}
//alert("widgetHeight = " + height + "; infoHeight = " + infoHeight + "; rows = " + numberOfRows);
//var divElement = document.getElementById('infoAreaContainer');
//alert(" infoHeight Div = " + divElement.style.height);
return height;
}
function onremove ()
{
if (window.vtMain)
vtMain.onRemove();
// remove all the pref keys here
if (window.widget) {
setPreferenceForKey(null, selectionPrefKey);
setPreferenceForKey(null, showAMPMPrefKey);
setPreferenceForKey(null, showLeadingZerosPrefKey);
setPreferenceForKey(null, hideSecondsPrefKey);
setPreferenceForKey(null, useDSTInsteadOfSummerPrefKey);
setPreferenceForKey(null, showMoonLinePrefKey);
setPreferenceForKey(null, showChangeInMinutesPrefKey);
setPreferenceForKey(null, sortByCountryPrefKey);
setPreferenceForKey(null, regionPrefKey);
setPreferenceForKey(null, placePrefKey);
}
}
function createKey (key)
{
return widget.identifier + "-" + key;
}
function setPreferenceForKey(pref, key)
{
//set pref for widget instance
widget.setPreferenceForKey(pref, createKey(key));
//consider setting global pref
//widget.setPreferenceForKey(pref, key);
}
function getPreferenceForKey (key, global)
{
//get pref for widget instance
var pref = widget.preferenceForKey(createKey(key));
//consider getting global pref
//if (pref == null && global)
// pref = widget.preferenceForKey(key);
return pref;
}